package ViewFragment;

import uimain.PrivateNotes;
import JsonModel.Group;
import Utilities.Configuration;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.adgroup.smartnote.CreateNoteExpenseActivity;
import com.adgroup.smartnote.DetailGroupActivity;
import com.adgroup.smartnote.R;
import com.adgroup.smartnote.SearchFriend;
import com.androidquery.AQuery;

import database.Database;

public class DetailGroupFragment extends SherlockFragment{
	ListView lv;
	ImageButton btn;
	ProgressBar processWaiting;
	TextView tvEmpty;
	private View v;
	Group g;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.detailgroup_details, container, false);
	}
	@SuppressWarnings("static-access")
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		lv = (ListView) getView().findViewById(R.id.listViewDetailGroupDetail);
		btn = (ImageButton) getView().findViewById(R.id.imageButtonCreateNoteDetailGroupDetail);
		processWaiting = (ProgressBar) getView().findViewById(R.id.progressBarWaitingDetailGroupDetail);
		tvEmpty = (TextView) getView().findViewById(R.id.textViewEmptyDetailGroupDetail);
		
		//add footer iv
		v = DetailGroupFragment.this.getLayoutInflater(savedInstanceState).from(DetailGroupFragment.this.getSherlockActivity()).inflate(R.layout.footerwating, null);
		lv.addFooterView(v);
		v.setVisibility(View.GONE);
		processWaiting.setVisibility(View.GONE);
		tvEmpty.setVisibility(View.GONE);
		
		//create note
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent i = new Intent(DetailGroupFragment.this.getSherlockActivity(), CreateNoteExpenseActivity.class);
				startActivityForResult(i, Configuration.requestCreateNoteExpense);
			}
		});
		//load logo group
		g = new Database(DetailGroupFragment.this.getSherlockActivity()).getGroup();
		if(g!=null && !g.getLink().equalsIgnoreCase("")){
			AQuery aq = new AQuery(DetailGroupFragment.this.getSherlockActivity());
			Bitmap placeholder = aq.getCachedImage(R.drawable.imageload);
			aq.id(R.id.imageViewLogoDetailGroupDetail).image(g.getLink(), true,
						true, 0, 0, placeholder, AQuery.FADE_IN_NETWORK, 1.0f);
		}
		
	}
}
